<template>
	<view class="mainpadding ">
		<view class="flexbetween " style="padding: 0 40rpx;">
			<view class="ershiba margin_right1" :class="zh_status?'fonweight xiaolan':'xiaohui'" @click="changesxFn(1)">综合</view>
			<view class="ershiba margin_right1" :class="sales_status?'fonweight xiaolan':'xiaohui'" @click="changesxFn(2)">销量</view>
			<view class="flexleft">
				<view class="ershiba margin_right1" :class="price_status?'fonweight xiaolan':'xiaohui'" @click="changesxFn(3)">价格</view>
				<view class="">
					<view class="sxjyxz" v-if="price_status==1"></view>
					<view class="sxjwxz" v-if="price_status!=1"></view>
					<view class="xsjxyxz" v-if="price_status==2"></view>
					<view class="xsjwxz" v-if="price_status!=2"></view>
				</view>
			</view>
		</view>
		<!-- 商品列表 -->
		<view class="flexbetween flex_wrap">
			<view class="shpbox margin_top" v-for="item in list.data" :key="item.id" @click="tzspxq(item.id)">
				<image class="sptup" :src="item.image_text" mode=""></image>
				<view class="" style="padding: 24rpx; background-color: #fff;">
					<view class="xiankuan ershiba">{{item.title}}</view>
					<view class="flexleft margin_top1">
						<view class="strongtext xiaohong margin_right1">￥{{item.price}}</view>
						<view class="smalltext xiaohui ">已售{{item.sales}}件</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				category_id: "",
				page: 1,
				limit: 12,
				list:{
					data:[]
				},
				zh_status:0,//0=不参与,1=综合查询
				price_status:0,//价格:0=不参与,1=降序,2=升序
				sales_status:0//0=不参与,1=销量排序
			}
		},
		onLoad(options) {
			this.category_id = options.id
			if(options.name){
				uni.setNavigationBarTitle({
					title:options.name
				})
			}
			
			this.init()
		},
		methods: {
			tzspxq(id) {
				uni.navigateTo({
					url: '/pages_homepage/shangpxq?id='+id
				})
			},
			changesxFn(val){
				if(val==1){
					this.zh_status = this.zh_status==1?0:1
					this.price_status = 0
					this.sales_status = 0
				}
				if(val==2){
					this.zh_status = 0
					this.sales_status = this.sales_status==1?0:1
					this.price_status = 0
				}
				if(val==3){
					this.zh_status = 0
					this.sales_status = 0
					this.price_status = this.price_status==0?1:this.price_status==1?2:0
				}
				this.init()
			},
			init(isPage, page) {
				let _this = this
				httpRequest.request('/api/goods/goodsList', 'GET', {
					page: page || 1,
					limit: _this.limit,
					category_id:this.category_id,
					zh_status:this.zh_status,
					price_status:this.price_status,
					sales_status:this.sales_status
				}).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
		}
	}
</script>

<style lang="scss" scoped>
	// 商品列表
	.sptup {
		width: 100%;
		height: 331rpx;
		border-radius: 24rpx 24rpx 0 0;
	}

	.shpbox {
		width: 48%;
		border-radius: 24rpx;
	}

	//结束
	.xsjwxz {
		margin-top: 4rpx;
		width: 0;
		height: 0;
		border-left: 4px solid transparent;
		border-right: 4px solid transparent;
		border-top: 5px solid #77767C;
	}

	.xsjxyxz {
		margin-top: 4rpx;
		width: 0;
		height: 0;
		border-left: 4px solid transparent;
		border-right: 4px solid transparent;
		border-top: 5px solid #2361FF;
	}

	.sxjwxz {
		width: 0;
		height: 0;
		border-left: 4px solid transparent;
		border-right: 4px solid transparent;
		border-bottom: 5px solid #77767C;
	}

	.sxjyxz {
		width: 0;
		height: 0;
		border-left: 4px solid transparent;
		border-right: 4px solid transparent;
		border-bottom: 5px solid #2361FF;
	}

	.ssousuobox1 {
		background-color: #f6f6f6;
		width: 80%;
		border-radius: 36rpx;
		padding: 10rpx 30rpx;
	}
</style>